package com.d3works.studio.web;

import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.d3works.studio.db.AppLoader;
import com.d3works.studio.db.repo.AppLoaderRepository;
import com.d3works.studio.service.loader.AppLoaderExportService;
import com.d3works.studio.service.loader.AppLoaderImportService;
import com.google.inject.Inject;

public class AppLoaderController {

  @Inject protected AppLoaderImportService appLoaderImportService;

  @Inject protected AppLoaderExportService appLoaderExportService;

  @Inject protected AppLoaderRepository appLoaderRepository;

  public void exportApps(ActionRequest request, ActionResponse response) {

    AppLoader appLoader = request.getContext().asType(AppLoader.class);
    appLoader = appLoaderRepository.find(appLoader.getId());
    appLoaderExportService.exportApps(appLoader);
    response.setReload(true);
  }

  public void importApps(ActionRequest request, ActionResponse response) {

    AppLoader appLoader = request.getContext().asType(AppLoader.class);
    appLoader = appLoaderRepository.find(appLoader.getId());
    appLoaderImportService.importApps(appLoader);
    response.setReload(true);
  }
}
